package com.groupsix.service.impl;

import com.groupsix.entity.Dormgrade;
import com.groupsix.mapper.DormgradeMapper;
import com.groupsix.service.DormgradeService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 宿舍卫生业务逻辑接口实现类
 * @date 2021/10/17 22:04
 */
@Service
public class DormgradeServiceImpl implements DormgradeService {

    @Autowired
    private DormgradeMapper dormgradeMapper;


    //分页查询
    @Override
    public PageInfo findPageInfo(Integer dId, String dDormbuilding, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = dormgradeMapper.totalCount(dId,dDormbuilding);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示宿舍信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormgrade> dormCleanList =	dormgradeMapper.getDormgradeList(dId,dDormbuilding,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(dormCleanList);
        }
        return pi;
    }

    @Override
    public List<Dormgrade> getAll(){
        List<Dormgrade> dormgradeList = dormgradeMapper.getAll();
        return dormgradeList;
    }

    //添加宿舍卫生信息
    @Override
    public int addDormgrade(Dormgrade dormgrade) {
        return dormgradeMapper.addDormgrade(dormgrade);
    }

    //通过id删除宿舍卫生信息
    @Override
    public int deleteDormgrade(Integer gId) {
        return dormgradeMapper.deleteDormgrade(gId);
    }

    //修改宿舍卫生信息
    @Override
    public int updateDormgrade(Dormgrade dormgrade) {
        return dormgradeMapper.updateDormgrade(dormgrade);
    }

    @Override
    public Dormgrade findDormgradeById (Integer gId){
        Dormgrade d = dormgradeMapper.findDormgradeById(gId);
        return  d;
    }
}
